package xujiwen.transport.servlet;

import xujiwen.transport.bean.CarInfo;
import xujiwen.transport.Mgr.CarInfoMgr;

import java.text.SimpleDateFormat;
import java.util.Date;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import xujiwen.transport.util.locker.Password;

/**
 * Servlet implementation class for Servlet: Register
 * 
 */
public class AddCar extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public AddCar() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	@Override
	protected void doGet(final HttpServletRequest request,
			final HttpServletResponse response) throws ServletException,
			IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	@Override
	protected void doPost(final HttpServletRequest request,final HttpServletResponse response) throws ServletException,IOException {
		CarInfoMgr cm = new CarInfoMgr();
		// 指明编码
		request.setCharacterEncoding("utf-8"); 
		
		//System.out.println(password + "\t" + email + "\t");
		try {
			final String cid = request.getParameter("addcid");
			final String oid = request.getParameter("oid");
			final String type = request.getParameter("addcartype");
			final int carClass = Integer.parseInt(request.getParameter("addcarclass"));
			final int load = Integer.parseInt(request.getParameter("addload"));
			
			final CarInfo car = new CarInfo();
		
			car.setCid(cid);
			car.setOwnerId(oid);
			car.setCarType(type);
			car.setCarClass(carClass);
			car.setLoading(load);
			cm.Save(car);
			System.out.println("添加车辆成功");
		} catch(final NumberFormatException nfex){
			//response.sendRedirect("err.jsp");
			System.out.println("提交错误");			
			return ;
		}
		response.sendRedirect("operate/carMgr.jsp?searchStr=");
	}
}